package com.kotlin.tsw.usercenter.presenter

import com.kotlin.tsw.baselibrary.ext.execute
import com.kotlin.tsw.baselibrary.persenter.BasePresenter
import com.kotlin.tsw.baselibrary.rx.BaseSubScriber
import com.kotlin.tsw.usercenter.data.protocol.UserInfo
import com.kotlin.tsw.usercenter.presenter.view.UserInfoView
import com.kotlin.tsw.usercenter.service.UploadService
import com.kotlin.tsw.usercenter.service.UserService
import javax.inject.Inject

class UserInfoPersenter @Inject constructor() : BasePresenter<UserInfoView>() {
    @Inject
    lateinit var userService: UserService
    @Inject
    lateinit var uploadService: UploadService

    fun getUploadToken() {
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()
        uploadService.getUploadToken().execute(object : BaseSubScriber<String>(mView) {
            override fun onNext(t: String) {
                mView.onGetUploadTokenResult(t)
            }
        }, lifecycleProvider)
    }

    fun editUser(userIcon: String, userName: String, userMobile: String, userGender: String, userSign: String) {
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()
        userService.editUser(userIcon, userName, userMobile, userGender, userSign)
                .execute(object : BaseSubScriber<UserInfo>(mView) {
                    override fun onNext(t: UserInfo) {
                        mView.onEditUserResult(t)
                    }
                }, lifecycleProvider)
    }

}